package DLSched;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalINIConfiguration;

/**
 *
 * @author G-spot
 */
public class WriteLink
{

    public static void write_links(ArrayList<String> links)
    {
        try
        {
            HierarchicalINIConfiguration config =
                    new HierarchicalINIConfiguration("config.ini");
            try
            {
                // Create file 
                FileWriter fstream = new FileWriter(config.getString("general.links_filepath"));
                BufferedWriter out = new BufferedWriter(fstream);

                Logger.getLogger(WriteLink.class.getName()).log(Level.INFO, "Writing links: {0}", links);
                
                for (int i = 0; i < links.size(); i++)
                {
                    out.write(links.get(i));
                    out.write("\n");
                }
                //Close the output stream
                out.close();
            }
            catch (Exception e)
            {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            }
        }
        catch (ConfigurationException ex)
        {
            Logger.getLogger(WriteLink.class.getName()).log(Level.SEVERE,
                    "Could not read file: config.ini", ex);
        }
    }
}
